package com.hd.json2mysql.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.hd.json2mysql.entity.Classes;
import com.hd.json2mysql.entity.Fields;
import com.hd.json2mysql.enums.ClassType;
import com.hd.json2mysql.mapper.CodeAnalysisMapper;
import com.hd.json2mysql.utils.IdGenerator;
import com.hd.json2mysql.utils.JsonReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class FieldsService {

    @Autowired
    private CodeAnalysisMapper codeAnalysisMapper;

    public void storeFields(JsonNode classNode, String classId) {

        Fields fields = new Fields();
        fields.setId(IdGenerator.generate32Id());
        fields.setClassId(classId);
        try {
            fields.setTypeKey(classNode.get("TypeKey").asText());
            fields.setTypeType(classNode.get("TypeType").asText());
        } catch (Exception e) {
            System.out.println("无此属性,跳过：" + e.getMessage());
        }
        codeAnalysisMapper.insertFields(fields);
    }
}
